package net.sx.minemodule.mvp.presenters;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;
import com.kedll.library.util.Log;
import com.kedll.library.util.ToastUtil;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.R;
import net.sx.minemodule.mvp.bean.GoodCollectBean;
import net.sx.minemodule.mvp.item.GoodCollectItem;

import java.util.List;

/**
 * 商品收藏
 *
 * @author 11470
 */
public class MineGoodCollectPresenter extends AbstractRefreshPresenter {
    private int pos = 1;

    public MineGoodCollectPresenter(RefreshingView mView) {
        super(mView);
        emptyItem.setResId(R.mipmap.mine_no_message);
        emptyItem.setContent("暂无消息");
        android.util.Log.d("zhengshibo", "MineGoodCollectPresenter: 1111");
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        android.util.Log.d("zhengshibo", "fetchData: 222222");
        if (isLoadMore) {
            pos++;
        }
        MineApiUtils.getCollectionList(pos,10, subModelList -> {
            android.util.Log.d("zhengshibo", "fetchData: 333333");
            List<GoodCollectBean> goodCollectBean = JSON.parseArray(subModelList.getItems(), GoodCollectBean.class);
            parserData(isLoadMore, goodCollectBean);
        }, throwable -> {
            android.util.Log.d("zhengshibo", "fetchData: 44444");
        });
    }

    public void removeGoodsItem(GoodCollectItem iItem) {
        MineApiUtils.delCollectionById(iItem.getData().getProductId(), o -> {
            adapter.removeItem(iItem);
            adapter.notifyDataSetChanged();
        }, throwable -> {

        });
    }
}
